#!/usr/bin/env sh

DISPLAY1="$(bspc query -M --names | awk -F: '{print $1}' | grep 'eDP1\|eDP-1\|VGA-0')"
[[ ! -z "$DISPLAY1" ]] && bspc monitor "$DISPLAY1" -d 1 2 3 4 5 6 7 8 9 && bspc config -m "$DISPLAY1" top_padding 17

[[ -z `pgrep enforce` ]] && ~/.bin/enforce "$DISPLAY1" '^1' &

bspc config border_width 1
bspc config window_gap 3
bspc config split_ratio 0.5
bspc config borderless_monocle false
bspc config single_monocle true
bspc config gapless_monocle false
bspc config focus_follows_pointer true
bspc config focused_border_color "#585858"
bspc config normal_border_color "#12181d"
bspc config active_border_color "#585858"
bspc config presel_feedback_color "#9e9e9e"
bspc config click_to_focus any
bspc config honor_size_hints false
bspc config ignore_ewmh_focus true

# External Rules
bspc config external_rules_command ~/.config/bspwm/external.sh

# Workspaces
bspc rule -a firefox follow=on desktop=^1
bspc rule -a firefoxdeveloperedition follow=on desktop=^1
bspc rule -a Qutebrowser follow=on desktop=^1
bspc rule -a Iceweasel follow=on desktop=^1
bspc rule -a TelegramDesktop follow=on desktop=^2 state=tiled
bspc rule -a Thunderbird follow=on desktop=^3
bspc rule -a Icedove follow=on desktop=^3
bspc rule -a URxvt:ranger follow=on desktop=^4 state=tiled
bspc rule -a *:Ranger follow=on desktop=^4 state=tiled
bspc rule -a JDownloader follow=off  desktop=^5
bspc rule -a *:RTorrent follow=off  desktop=^5
bspc rule -a Lxappearance follow=on desktop=^6 state=floating
bspc rule -a Anydesk follow=on desktop=^6 state=tiled
bspc rule -a Remmina follow=on desktop=^6 state=tiled
bspc rule -a qt5ct follow=on desktop=^6 state=floating
bspc rule -a URxvt:music follow=on desktop=^7 state=tiled
bspc rule -a *:Ncmpcpp follow=on desktop=^7 state=tiled
bspc rule -a mpv follow=on desktop=^7 state=tiled
bspc rule -a obs follow=on desktop=^7 state=tiled
bspc rule -a cantata follow=on desktop=^7 state=tiled
bspc rule -a Easytag follow=on desktop=^7 state=tiled
bspc rule -a *:libreoffice follow=off desktop=^8 state=tiled
bspc rule -a Soffice follow=off desktop=^8
bspc rule -a Zathura follow=on desktop=^8 state=tiled
bspc rule -a Emacs follow=on desktop=^9 state=tiled
bspc rule -a Remacs follow=on desktop=^9 state=tiled
bspc rule -a Wine follow=off desktop=^6 state=tiled

# Floating apps
bspc rule -a sxiv follow=off state=floating
bspc rule -a URxvt:Terminal follow=off state=floating center=on
bspc rule -a *:Terminal follow=off state=floating center=on
bspc rule -a *:Buscando follow=off state=floating center=on

# Xresources
xrdb ~/.Xresources &
# Wallpaper
[[ -z $(pgrep feh) ]] && feh --bg-fill $HOME/.dots/walls/03.jpg &

# i3lock Fancy
[[ -z $(pgrep xss-lock) ]] && xss-lock -- i3lock-fancy-dualmonitor -p -f 'PragmataPro-Mono-Regular' &
# clipboard
[[ -z $(pgrep clipboard) ]] && ~/.bin/clipboard &
# panel
[[ -z $(pgrep panel) ]] && ~/.bin/panel &
# udiskie
[[ -z $(pgrep udiskie) ]] && udiskie &
# sxhkd
[[ -z $(pgrep sxhkd) ]] && sxhkd &
# xcompmgr
[[ -z $(pgrep xcompmgr) ]] && xcompmgr -c -C -t-5 -l-5 -r4.2 &

#! /bin/sh

window_id=$1
class=$2
instance=$3

#WM_WINDOW_ROLE Rules
role=$(xprop -id $1 | grep WM_WINDOW_ROLE | awk -F '"' '{print $2}')
case "$role" in
  quake) #Tilix Quake
    echo "state=floating"
    echo "border=off"
    ;;
  pop-up|bubble|task_dialog|Preferences|dialog|menu)
    echo "state=floating"
    ;;
  About|Organizer|Buscando) #Firefox
    echo "state=floating"
    ;;
esac
